﻿@{
    ViewBag.Title = "报表管理";
    ViewBag.MenuIndex = 3;
    List<Xwork.SEO.SearchEngine> engines = (List<Xwork.SEO.SearchEngine>)ViewData["engines"];
}

@model IPagedList<Xwork.SEO.SeoKeyword>
<div class="ny">
    <div class="ny_kb9"></div>
    <form name="myform" action="@Url.Action("index")" method="get">
        <div class="search">
            <span>
                选择站点:   
                   @Html.DropDownList("siteId", (IEnumerable<SelectListItem>)ViewData["siteId"], "选择站点", new { onchange = "document.myform.submit();" })
            </span>
            <span style="margin-left:10px;">
                关键词：<input type="text" name="keyword" value="">
            &nbsp;选择日期：<input name="begin_date" type="text" value="" id="begin_date" class="Wdate" style="width:100px;" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'});"> - <input name="end_date" type="text" value="" id="end_date" class="Wdate" style="width:100px;" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'});">   
            </span>
            <span style="margin-left:10px;">
                <input type="submit" value="" id="bg_07">
            </span> 
            <div class="clear"></div>
        </div>
    </form>
    <table id="myTable" style="width:990px; margin-bottom:10px;" class="tablesorter" border="0" cellpadding="0" cellspacing="0">
    	<thead>
        	<tr class="even">
                <th width="19%"><h3>站点</h3></th>
                <th width="12%"><h3>关键词</h3></th>
                @foreach (var item in engines)
                {
                    <th class="header"><h3>@(item.Name)第1页</h3></th>
                    <th class="header"><h3>@(item.Name)第2页</h3></th>
                }
                <th width="9%" class="header"><h3>累计消费</h3></th>
            </tr>
        </thead>
        <tbody>
            @foreach (var item in Model)
            {
                decimal sum = 0;
                <tr class="even">
                <td><a target="_blank" href="@("http://"+item.SeoSite.SiteUrl)">@item.SeoSite.SiteUrl</a></td>
                <td>@item.KeywordName</td>
                @foreach (var eng in engines)
                {
                    var sumpage1 = item.SeoLogs.Where(p => p.PageIndex == 1 && p.SearchEngineID == eng.ID).Sum(p => p.Amount);
                    var sumpage2 = item.SeoLogs.Where(p => p.PageIndex == 2 && p.SearchEngineID == eng.ID).Sum(p => p.Amount);
                    sum += sumpage1 + sumpage2;
                <td>@(sumpage1 == 0 ? "-" : sumpage1.ToString())</td>
                <td>@(sumpage2 == 0 ? "-" : sumpage2.ToString())</td>
                }
                <td>@sum</td>
                </tr>
            }
        </tbody>
    </table>
    <div style="text-align:right;">
        @Html.PagedListPager(Model, p => Url.Action("userlist", new { pageindex = p }))
    </div>
</div>